/**
 * 
 */
package com.kingcore.pda.core.util;

import java.lang.reflect.Method;

import org.apache.commons.lang.StringUtils;

/**
 * @author Zeven
 *
 */
public class LangUtil {
	
	public static void setProperty(Object obj, String name,
			String val) throws Exception {
		//setProperty(colBean.getClass(), name, val);
		Class<?> clazz = obj.getClass();
		Method[] methods = clazz.getMethods();
		String setterName = "set"+StringUtils.capitalize( name );  //首字母转为大写
		for (Method method : methods) {
			if (method.getName().equalsIgnoreCase( setterName )) {  //反射不分大小写
				try {
					Method setMethod = clazz.getMethod(     //.getClass()
							setterName, val.getClass());   
                    setMethod.invoke(obj, val);   
					//method.invoke(obj, val, val.getClass());
				} catch (Exception e) {
					e.printStackTrace();
					throw e;
				} 
			}
			
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("=="+StringUtils.capitalize("capitalize") );
	}

}
